package com.lxmes.business.service.Impl;

import com.lxmes.business.domain.*;
import com.lxmes.business.service.ChukuInfoWebServiceService;
import com.lxmes.business.service.ICcChukuInfoService;
import com.lxmes.common.utils.HttpClientUnit;
import com.lxmes.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

@Component
@Service
public class ChukuInfoWebServiceServiceImpl implements ChukuInfoWebServiceService {
    private final WLogin wLogin;
    @Autowired
    private ICcChukuInfoService ccChukuInfoMapper;
    @Autowired
    public ChukuInfoWebServiceServiceImpl(WLogin wLogin) {
        this.wLogin = wLogin;
    }

    @Override
    public Map<String, String> zhixingUCuku(Long[] ids) {
        SaleoutHead head = new SaleoutHead();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        head.setDdate(sdf.format(new Date()));
        head.setCwhcode("02");
        head.setCrdcode("4");
        head.setCrdname("销售出库");
        head.setCcusabbname("济南森峰激光科技股份有限公司");
        head.setCcuscode("0029");
        head.setCmaker(SecurityUtils.getUsername());
        List<Object> list = new ArrayList<>();

        for (int i = 0; i <ids.length ; i++) {
            CcChukuInfo info = ccChukuInfoMapper.selectCcChukuInfoById(ids[i]);
            SaleoutBody body = new SaleoutBody();
            body.setCinvm_unit(info.getUnit());
            body.setIquantity(info.getCkNum().doubleValue());
            body.setCinvcode(info.getItemCode());
            body.setIrowno(Integer.toString(i+1));
            body.setIunitcost(info.getPrice().doubleValue());
            body.setIprice(info.getPrice().doubleValue());
            list.add(body);
        }
        Map<String, String> StringMap = HttpClientUnit.webServiceXml(head, list,wLogin.toString(), "http://192.168.3.249:10000/u8api.asmx/SaleOutAdd");
        return StringMap;
    }
}
